import 'package:flutter/material.dart';
import 'package:ichinesereader/models/report/bookchartdata.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:syncfusion_flutter_charts/charts.dart';
import 'package:get/get.dart';

class BookTopicsWidget extends StatelessWidget {
  BookTopicsWidget({Key? key, required this.bookchartdata}) : super(key: key);
  final List<BookChartData> bookchartdata;

  @override
  Widget build(BuildContext context) {
    Log.debug('build BookTopicsWidget');

    TooltipBehavior _tooltipbehavior = TooltipBehavior(enable: true);
    return SfCircularChart(
        title: ChartTitle(
          alignment: ChartAlignment.near,
          text: 'Number of Books by Topics'.tr,
          textStyle: TextStyle(
              fontFamily: 'Montserrat',
              color: Get.isDarkMode
                  ? Get.theme.primaryColorDark
                  : Get.theme.primaryColorLight),
        ),
        legend: Legend(
          isVisible: true,
          textStyle: TextStyle(
              fontFamily: 'Montserrat',
              color: Get.isDarkMode
                  ? Get.theme.primaryColorDark
                  : Get.theme.primaryColorLight),
        ),
        tooltipBehavior: _tooltipbehavior,
        series: <CircularSeries>[
          PieSeries<BookChartData, String>(
              dataSource: bookchartdata,
              xValueMapper: (BookChartData data, _) => data.item,
              yValueMapper: (BookChartData data, _) => data.account,
              animationDuration: 1000,
              dataLabelSettings: DataLabelSettings(
                isVisible: true,
                //  labelIntersectAction: LabelIntersectAction.shift,
                // labelPosition: ChartDataLabelPosition.outside,
                // connectorLineSettings: ConnectorLineSettings(
                //   type: ConnectorType.curve, length: '25%')
              ))
        ]);
  }
}
